using Unity.Entities;
using UnityEngine;

namespace Kickball.Step1
{
    public struct Config : IComponentData
    {
        public int ObstaclesNumRows;
        public int ObstaclesNumColumns;
        public float ObstacleRadius;
        public float ObstacleGridCellSize;
        public float ObstacleOffset;
        public float PlayerOffset;
        public float PlayerSpeed;
        public float BallStartVelocity;
        public float BallVelocityDecay;
        public float BallKickingRangeSq;
        public float BallKickForce;
        public Entity PlayerPrefab;
        public Entity ObstaclePrefab;
        public Entity BallPrefab;
    }

    public class ConfigAuthoring : MonoBehaviour
    {
        [Header("障碍行数")] public int ObstaclesNumRows;
        [Header("障碍列数")] public int ObstaclesNumColumns;
        [Header("障碍半径")] public float ObstacleRadius;
        [Header("障碍基础间距")] public float ObstacleGridCellSize;
        [Header("障碍间距的最大间距差")] public float ObstacleOffset;
        [Header("球员生成位置相对障碍中心的距离")] public float PlayerOffset;
        [Header("球员速度")] public float PlayerSpeed;
        [Header("球的初始速度")] public float BallStartVelocity;
        [Header("球的速度衰减")] public float BallVelocityDecay;
        [Header("踢球范围")] public float BallKickingRange;
        [Header("踢球的力")] public float BallKickForce;
        [Header("障碍物预制体")] public GameObject ObstaclePrefab;
        [Header("球员预制体")] public GameObject PlayerPrefab;
        [Header("球预制体")] public GameObject BallPrefab;

        class Baker : Baker<ConfigAuthoring>
        {
            public override void Bake(ConfigAuthoring authoring)
            {
                var entity = GetEntity(TransformUsageFlags.None);
                AddComponent(entity, new Config
                {
                    ObstaclesNumRows = authoring.ObstaclesNumRows,
                    ObstaclesNumColumns = authoring.ObstaclesNumColumns,
                    ObstacleRadius = authoring.ObstacleRadius,
                    ObstacleGridCellSize = authoring.ObstacleGridCellSize,
                    ObstacleOffset = authoring.ObstacleOffset,
                    PlayerOffset = authoring.PlayerOffset,
                    PlayerSpeed = authoring.PlayerSpeed,
                    BallStartVelocity = authoring.BallStartVelocity,
                    BallVelocityDecay = authoring.BallVelocityDecay,
                    BallKickingRangeSq = authoring.BallKickingRange,
                    BallKickForce = authoring.BallKickForce,
                    PlayerPrefab = GetEntity(authoring.PlayerPrefab, TransformUsageFlags.Dynamic),
                    ObstaclePrefab = GetEntity(authoring.ObstaclePrefab, TransformUsageFlags.Dynamic),
                    BallPrefab = GetEntity(authoring.BallPrefab, TransformUsageFlags.Dynamic),
                });
            }
        }
    }
}